#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int solve(int money, const vector<pair<int, int>>& moneyCount)
{
	int count = 0;
	for (int i = moneyCount.size() - 1; i >= 0; i--)
	{
		int c = 0;
		c = money / moneyCount[i].first;

		if (c > moneyCount[i].second)
		{
			c = moneyCount[i].second;
		}

		money -= c * moneyCount[i].first;
		count += c;

		if (money == 0)
		{
			break;
		}
	}
	if (money != 0)
	{
		return -1;
	}
	return count;
}

int main()
{
	int money = 1234;
	vector<pair<int, int>> moneyCount = { { 1, 30 }, { 2, 10 }, { 5, 40 }, { 10, 30 }, { 20, 10},{50, 10}, { 100, 10 } };
	cout << solve(money, moneyCount) << endl;
}
	 
